001 /*
002 * Copyright 2004 Stephen J. McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.metro.info;
020
021 import net.dpml.lang.ValuedEnum;
022
023 /**
024 * Logging priority enumeration.
025 *
026 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
027 * @version 1.0.2
028 */
029 public final class Priority extends ValuedEnum
030 {
031 static final long serialVersionUID = 1L;
032
033 /**
034 * ERROR logging priority.
035 */
036 public static final Priority ERROR = new Priority( "error", 40 );
037
038 /**
039 * WARN logging priority.
040 */
041 public static final Priority WARN = new Priority( "warn", 30 );
042
043 /**
044 * INFO logging priority.
045 */
046 public static final Priority INFO = new Priority( "info", 20 );
047
048 /**
049 * DEBUG logging priority.
050 */
051 public static final Priority DEBUG = new Priority( "debug", 10 );
052
053 /**
054 * DEBUG logging priority.
055 */
056 public static final Priority TRACE = new Priority( "trace", 5 );
057
058 /**
059 * Array of static priority enumeration values.
060 */
061 private static final Priority[] ENUM_VALUES =
062 new Priority[]{ERROR, WARN, INFO, DEBUG, TRACE};
063
064 /**
065 * Returns an array of priority enum values.
066 * @return the priority policies array
067 */
068 public static Priority[] values()
069 {
070 return ENUM_VALUES;
071 }
072
073 /**
074 * Internal constructor.
075 * @param label the enumeration label.
076 * @param index the enumeration index.
077 */
078 private Priority( String label, int index )
079 {
080 super( label, index );
081 }
082
083 /**
084 * Parse the supplied value into a logging priority constant.
085 * @param value the value to parse
086 * @return the logging priority constant
087 * @exception IllegalArgumentException if the value cannot be mapped
088 * to a logging priority enumeration name
089 */
090 public static Priority parse( String value ) throws IllegalArgumentException
091 {
092 if( value.equalsIgnoreCase( "error" ) )
093 {
094 return ERROR;
095 }
096 else if( value.equalsIgnoreCase( "warn" ) )
097 {
098 return WARN;
099 }
100 else if( value.equalsIgnoreCase( "info" ) )
101 {
102 return INFO;
103 }
104 else if( value.equalsIgnoreCase( "debug" ) )
105 {
106 return DEBUG;
107 }
108 else if( value.equalsIgnoreCase( "trace" ) )
109 {
110 return TRACE;
111 }
112 else
113 {
114 final String error =
115 "Unrecognized logging priority [" + value + "]";
116 throw new IllegalArgumentException( error );
117 }
118 }
119
120 /**
121 * Return a string representation of the priority constant.
122 * @return the string value
123 */
124 public String toString()
125 {
126 return getName().toUpperCase();
127 }
128 }
129